<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class CI_Controls{

	var $atributos= array();
	var $value='';
	var $label='';
	var $uid;
	var $CI;

	function __construct(){
		$this->CI =& get_instance();
		$this->CI->load->helper('url');
		$this->uid=uniqid(php_uname('n').'-control-');
		$this->att('uid',$this->uid);
		log_message('debug', "Controls Class Initialized");
	}


	function __toString(){
		return $this->draw();
	}

	function addControl(CI_Controls $control){
		$this->value.=$control->draw();
	}

	function att($key, $value=NULL){
		if($value){
			$this->atributos[$key]=$value;
		} else if(isset($this->atributos[$key])){
			return $this->atributos[$key];
		} else{
			return false;
		}
	}

	protected function drawLabel(){
		$label='';
		if(!empty($this->label)){
			$label.='<label';
			if(!empty($this->atributos['id'])){
				$label.=' id="'.$this->atributos['id'].'-label" for="'.$this->atributos['id'].'"';
			}
			if(!empty($this->atributos['class'])){
				$label.=' class="'.$this->atributos['class'].'-label '.get_class($this).'-label"';
			}
			$label.='>';
			$label.=$this->label;
			$label.='</label>';
		}
		return $label;
	}

	public function draw(){
		$buffer='';
		$buffer.=$this->drawLabel();
		$buffer.=$this->drawContent();
		return $buffer;
	}

	/**
	 * metodo para devolver los atributos como cadena
	 * @param string $sufijo
	 * @return string
	 */
	protected function parseAtributos($sufijo=''){

		$atributos='';
		foreach ($this->atributos as $key => $value) {
			if($key=='class'){
				$atributos.=' '.$key.'="'.$value.$sufijo.'"';
			} else if($key=='id'){
				$atributos.=' '.$key.'="'.$value.$sufijo.'"';
			} else if(is_bool($value) && $value){
				$atributos.=' '.$key;
			} else {
				$atributos.=' '.$key.'="'.$value.'"';
			}
		}

		return $atributos;

	}

	/**
	 * Metodo para pasarle los atributos principales a otro elemento del control
	 * @param string $sufijo
	 * @return multitype:string
	 */
	protected function heredarAtributos($sufijo=''){

		$modificados=array();
		if(!empty($this->atributos['class'])){
			$modificados['class']=$this->atributos['class'].$sufijo;
		}
		if(!empty($this->atributos['id'])){
			$modificados['id']=$this->atributos['id'].$sufijo;
		}
		return $modificados;
	}

}

$controls= BASEPATH.'libraries/controls/';
require_once $controls.'anchor.php';
require_once $controls.'article.php';
require_once $controls.'accordion.php';
require_once $controls.'form.php';
require_once $controls.'autocomplete.php';
require_once $controls.'cloudCarousel.php';
require_once $controls.'combo.php';
require_once $controls.'div.php';
require_once $controls.'fbWall.php';
require_once $controls.'galleria.php';
require_once $controls.'h.php';
require_once $controls.'header.php';
require_once $controls.'img.php';
require_once $controls.'inputs.php';
require_once $controls.'kenBurns.php';
require_once $controls.'li.php';
require_once $controls.'mapGoogle.php';
require_once $controls.'nav.php';
require_once $controls.'pagination.php';
require_once $controls.'section.php';
require_once $controls.'fluxslider.php';
require_once $controls.'span.php';
require_once $controls.'tab.php';
require_once $controls.'tree.php';
require_once $controls.'ul.php';
require_once $controls.'rhinoSlider.php';
require_once $controls.'flexslider.php';
require_once $controls.'fileManager.php';